#include "mywidget.h"
#include "demo.h"
#include "ui_mywidget.h"
#include <QDebug>
#include <QPalette>

MyWidget::MyWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MyWidget) {
    ui->setupUi(this);

    // this->setWindowFlags(Qt::FramelessWindowHint);//无边框 置顶

    // 设置窗口背景透明
    //  this->setAttribute(Qt::WA_TranslucentBackground);
    // this->setStyleSheet("QWidget{border-width:2px;border-radius:5px;font-size:15px;color:black;border:2px
    // solid rgb(145,135,255);}");

    // 设置样式
    this->setStyleSheet("background-color:white");
    // 重置页面
    this->resize(500, 550);
    this->setFixedSize(500, 550);
    this->setWindowTitle("全功能测试软件");

    // 应用最大的垂直layout
    this->login_VBL = new QVBoxLayout();
    this->login_VBL->setMargin(0); // 边缘空白为0
    this->login_VBL->setMargin(0);
    this->setLayout(this->login_VBL);

    // 添加上方widget
    this->login_up_Widget = new QWidget();
    this->login_up_Widget->setFixedSize(500, 200);
    this->login_up_Widget->setStyleSheet("background-color:white;");

    // 图片
    this->up_image_Label = new QLabel();
    this->up_image_Label->setFixedSize(300, 100);
    QImage *img1 = new QImage;
    img1->load("C:/Users/Administrator/Desktop/all/images/u7.jpg");
    img1->scaled(this->up_image_Label->size(), Qt::KeepAspectRatio);
    this->up_image_Label->setScaledContents(true);
    this->up_image_Label->setPixmap(QPixmap::fromImage(*img1));
    this->login_up_img_VBL = new QVBoxLayout();
    this->login_up_img_VBL->setAlignment(Qt::AlignCenter);
    this->login_up_img_VBL->addWidget(this->up_image_Label);
    this->login_up_img_Widget = new QWidget();
    this->login_up_img_Widget->setLayout(this->login_up_img_VBL);

    // “智能终端全功能测试软件”
    this->up_text_Label = new QLabel();
    this->up_text_Label->setText("智能终端全功能测试软件");
    QFont font1;
    font1.setPointSize(20);
    font1.setFamily("微软雅黑");
    font1.setBold(true);
    this->up_text_Label->setFont(font1);                         // 字体
    this->up_text_Label->setStyleSheet("color: rgb(2,111,105)"); // 颜色
    this->login_up_text_VBL = new QVBoxLayout();
    this->login_up_text_VBL->setAlignment(Qt::AlignCenter);
    this->login_up_text_VBL->addWidget(this->up_text_Label);
    this->login_up_text_Widget = new QWidget();
    this->login_up_text_Widget->setLayout(this->login_up_text_VBL);

    // 加到上方widget中
    this->login_up_VBL = new QVBoxLayout();
    this->login_up_VBL->setMargin(0);
    this->login_up_VBL->addWidget(this->login_up_img_Widget);
    this->login_up_VBL->addWidget(this->login_up_text_Widget);
    this->login_up_Widget->setLayout(this->login_up_VBL);
    this->login_VBL->addWidget(this->login_up_Widget);

    // 添加下方widget
    this->login_down_Widget = new QWidget();
    // this->login_down_VBL = new QVBoxLayout();
    this->login_down_Widget->setFixedSize(500, 350);
    this->login_down_Widget->setStyleSheet("background-color:rgb(239,253,253);");

    // 用户名
    this->down_user_Label = new QLabel();
    this->down_user_Label->setText("用户名");
    QFont font2;
    font2.setPointSize(15);
    font2.setFamily("微软雅黑");
    this->down_user_Label->setFont(font2);                  // 字体
    this->down_user_Label->setStyleSheet("color: #333333"); // 颜色
    this->down_user_LineEdit = new QLineEdit();
    this->down_user_LineEdit->setFixedSize(300, 30);
    this->down_user_LineEdit->setStyleSheet(
            "QLineEdit{border-width:2px;border-radius:5px;font-size:15px;color:black;"
            "border:2px  solid rgb(215,215,215);}"
            "QLineEdit:hover{border-width:2px;border-radius:5px;font-size:15px;color:"
            "black;border:1px solid rgb(215,215,215);}");
    this->login_down_user_HBL = new QHBoxLayout();
    this->login_down_user_HBL->addSpacing(50);
    this->login_down_user_HBL->addWidget(this->down_user_Label);
    this->login_down_user_HBL->addWidget(this->down_user_LineEdit);
    this->login_down_user_HBL->addSpacing(50);
    this->login_down_user_Widget = new QWidget();
    this->login_down_user_Widget->setLayout(this->login_down_user_HBL);

    // 密码
    this->down_pwd_Label = new QLabel();
    this->down_pwd_Label->setText("密   码");
    this->down_pwd_Label->setFont(font2);
    this->down_pwd_Label->setStyleSheet("color: #333333"); // 颜色
    this->down_pwd_LineEdit = new QLineEdit();
    this->down_pwd_LineEdit->setFixedSize(300, 30);
    this->down_pwd_LineEdit->setEchoMode(QLineEdit::Password);
    this->down_pwd_LineEdit->setStyleSheet(
            "QLineEdit{border-width:1px;border-radius:5px;font-size:15px;color:black;"
            "border:2px solid rgb(215,215,215);}"
            "QLineEdit:hover{border-width:2px;border-radius:5px;font-size:15px;color:"
            "black;border:1px solid rgb(215,215,215);}");
    this->login_down_pwd_HBL = new QHBoxLayout();
    this->login_down_pwd_HBL->addSpacing(50);
    this->login_down_pwd_HBL->addWidget(this->down_pwd_Label);
    this->login_down_pwd_HBL->addWidget(this->down_pwd_LineEdit);
    this->login_down_pwd_HBL->addSpacing(50);
    this->login_down_pwd_Widget = new QWidget();
    this->login_down_pwd_Widget->setLayout(this->login_down_pwd_HBL);
    // 模式
    this->down_mode_Label = new QLabel();
    this->down_mode_Label->setText("模   式");
    this->down_mode_Label->setFont(font2);
    this->down_mode_Label->setStyleSheet("color: #333333"); // 颜色
    this->down_mode_ComboBox = new QComboBox();
    this->down_mode_ComboBox->setFixedSize(300, 30);
    this->down_mode_ComboBox->addItem("单机模式");
    this->down_mode_ComboBox->addItem("......");
    this->down_mode_ComboBox->setStyleSheet(
            "QComboBox {" // 未下拉时
            "border:2px solid rgb(215,215,215);border-radius:5px;"
            "padding:1px 1px 1px 3px;"
            "font-size:15px;color:#7f7f7f;font-family:Microsoft YaHei UI;}"
            "QComboBox:checked {" // 下拉时
            "border:1px solid #069aae;border-radius:5px;"
            "}"
            "QComboBox QAbstractItemView{" // 下拉后，整个下拉窗体样式
            "outline: 0px solid gray;"     // 选定项的虚线框
            "border:1px solid #eeeeee;border-radius:10px;" // 整个下拉窗体的边框
            "color:#7f7f7f;font-size:15px;font-family:Microsoft YaHei UI;"
            "background-color: #ffffff;" // 整个下拉窗体的背景色
            "selection-color:#333333;selection-background-color:#4090ff;}" // 被选中的背景色
            /* 下拉箭头样式 */
            "QComboBox::drop-down {subcontrol-origin: padding;subcontrol-position: "
            "top right;"
            "width: 16px;"
            "border-left: 0px solid darkgray;"
            "border-top-right-radius: 4px;"
            "border-bottom-right-radius: 4px;}"
            // "QComboBox::down-arrow {image:url(:/image/gdt_xx_n.png); padding-right:
            // 10px;}" "QComboBox::down-arrow:on {image:url(:/image/gdt_xs_n.png);
            // padding-right: 10px;}"
    );
    this->login_down_mode_HBL = new QHBoxLayout();
    this->login_down_mode_HBL->addSpacing(50);
    this->login_down_mode_HBL->addWidget(this->down_mode_Label);
    this->login_down_mode_HBL->addWidget(this->down_mode_ComboBox);
    this->login_down_mode_HBL->addSpacing(50);
    this->login_down_mode_Widget = new QWidget();
    this->login_down_mode_Widget->setLayout(this->login_down_mode_HBL);
    // 登录
    this->down_login_PushBtn = new QPushButton(this);
    this->down_login_PushBtn->setFixedSize(300, 40);
    this->down_login_PushBtn->setText("登  录");
    this->down_login_PushBtn->setStyleSheet(
            // 正常状态样式
            "QPushButton{"
            "background-color:#00BFBF;" // 背景色（也可以设置图片）
            "border-style:outset;"      // 边框样式（inset/outset）
            "border-width:4px;"         // 边框宽度像素
            "border-radius:10px;"       // 边框圆角半径像素
            "border-color:rgba(255,255,255,30);"             // 边框颜色
            "font:bold 18px;font-family:Microsoft YaHei UI;" // 字体，字体大小
            "color:rgba(255,255,255,255);"                   // 字体颜色
            "padding:6px;"                                   // 填衬
            "}"
            // 鼠标按下样式
            "QPushButton:pressed{"
            "background-color:#6666FF;"
            "border-color:rgba(255,255,255,30);"
            "border-style:inset;"
            "color:rgba(0,0,0,100);"
            "}"
            // 鼠标悬停样式
            "QPushButton:hover{"
            "background-color:#3caaaa;"
            "border-color:rgba(255,255,255,200);"
            "}");
    this->login_down_login_HBL = new QHBoxLayout();
    this->login_down_login_HBL->addWidget(this->down_login_PushBtn);
    this->login_down_login_Widget = new QWidget();
    this->login_down_login_Widget->setLayout(this->login_down_login_HBL);
    // other
    this->down_Info_Label = new QLabel();
    this->down_Info_Label->setText("适用于DL/T 698.45 版本：V1.22.01");
    font2.setPointSize(12);
    this->down_Info_Label->setFont(font2);
    this->down_Info_Label->setStyleSheet("color: #7f7f7f"); // 颜色
    this->down_AdvancedSetting_PushBtn = new QPushButton(this);
    this->down_AdvancedSetting_PushBtn->setText("高级设置");
    this->down_AdvancedSetting_PushBtn->setFixedSize(100, 30);
    this->down_AdvancedSetting_PushBtn->setStyleSheet(
            // 正常状态样式
            "QPushButton{"
            "border-style:outset;"               // 边框样式（inset/outset）
            "border-color:rgba(255,255,255,30);" // 边框颜色
            "font:14px;font-family:Microsoft YaHei UI;" // 字体，字体大小
            "color:#333333;"                            // 字体颜色
            "}");
    QIcon gjszicon; // 新建QIcon对象
    gjszicon.addFile(
            "C:/Users/Administrator/Desktop/all/images/u12.png"); // 让QIcon对象指向想要的图标
    this->down_AdvancedSetting_PushBtn->setIcon(gjszicon); // 给按钮添加图标
    this->login_down_other_HBL = new QHBoxLayout();
    this->login_down_other_HBL->addWidget(this->down_Info_Label);
    this->login_down_other_HBL->addWidget(this->down_AdvancedSetting_PushBtn);
    this->login_down_other_Widget = new QWidget();
    this->login_down_other_Widget->setLayout(this->login_down_other_HBL);

    this->login_down_VBL = new QVBoxLayout();
    this->login_down_VBL->setMargin(0);
    this->login_down_VBL->addSpacing(40);
    this->login_down_VBL->addWidget(this->login_down_user_Widget);
    this->login_down_VBL->addWidget(this->login_down_pwd_Widget);
    this->login_down_VBL->addWidget(this->login_down_mode_Widget);
    this->login_down_VBL->addSpacing(20);
    this->login_down_VBL->addWidget(this->login_down_login_Widget);
    this->login_down_VBL->addSpacing(20);
    this->login_down_VBL->addWidget(this->login_down_other_Widget);

    this->login_down_Widget->setLayout(this->login_down_VBL);

    this->login_VBL->addWidget(this->login_down_Widget);

    connect(this->down_login_PushBtn, &QPushButton::clicked, this,
            &MyWidget::LoginButtonClicked);
    connect(this->down_AdvancedSetting_PushBtn, &QPushButton::clicked, this,
            &MyWidget::AdvancedSettingButtonClicked);



}

MyWidget::~MyWidget() { delete ui; }

void MyWidget::LoginButtonClicked() {

    if (down_user_LineEdit->text().toStdString()=="admin"&&down_pwd_LineEdit->text().toStdString()=="1234"){
        demo *d = new demo();
        d->show();
        this->close();
    }


}

void MyWidget::AdvancedSettingButtonClicked() {
    Dialog_AdvancedSetting *dia_advancedsetting = new Dialog_AdvancedSetting();
    // dia_advancedsetting->setWindowFlags(Qt::WindowMinMaxButtonsHint);
    dia_advancedsetting->show();
}
